<%@ page language="java" import="com.xb.loan.admin.Constants" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

	<span class="btn_menu"></span>
	<h1><a href="#">兴宝爱车管理平台</a></h1>
	    <div class="nav_btn">
	        <span class="username">欢迎，<%=session.getAttribute(Constants.SESSION_LOGIN_NAME)%></span>
	        <q></q>
	        <a href="javascript:;" class="top_nav3" id="exit_Login" title="退出系统"></a>
	    </div>
    
<div id="mask" style="height: 100%; display: none;"></div>
<div id="updateBox" class="popup_box change_psd" style="width: 440px;height: 280px;display: none;">
        <h2>修改密码</h2>
        <a href="javascript:;" class="close close_bar">
       
        </a>
        <div class="pop_content pop_cont" style="min-height: 137px; padding: 24px 70px 10px 52px">
            <div class="type pop_cont_nav">
                <label>原密码</label>
                <span><input type="password" id="oldpwd" name="oldpwd"></span>
            </div>
            <div class="pop_cont_nav">
                <label>新密码</label>
                <span><input type="password" id="newpwd" name="newpwd"></span>
            </div>
            <div class="pop_cont_nav" style="margin-bottom:0px;">
                <label>确认密码</label>
                <span><input type="password" id="compwd" name="compwd"></span>
            </div>
            <div style="color:red">
            	<label style="width:70px;float:left;" ></label><label id="errorMsg"></label>
            </div>
        </div>
        <div class="pop_button">
        	<a id="confirm_ok_update" href="javascript:updateLoginPwd();">确定</a>
        	<a id="confirm_cancel" href="javascript:;">取消</a>
        </div>
</div>
<!--提示是否退出登录-->
<div id="exitBox" class="exit_box popup_box" style="width: 312px;margin-left: -156px;display: none;" >
        <h2>提示</h2>
        <a href="javascript:;" class="close">
            <span class="white">×</span>
        </a>
        <div class="pop_content">
                <p class="txt_c pd_t_35">您确定退出登录？</p>
        </div>
        <div class="pop_button">
            <a id="confirm_ok" href="logout">确定</a>
            <a id="confirm_cancel" class="cancel_exit" href="javascript:;">取消</a>
        </div>
</div>

<script type="text/javascript">
var loginUserType = '${loginUserType}';
$(document).ready(function(e) {
	//操作鼠标划过
	var $btn_operate=$(".operate .btn_operate").children("a");
	var $operate_list=$(".operate ul");
	$btn_operate.mouseenter(function(){
		$(this).css("visibility","hidden").siblings("ul").show();	
	})
	$operate_list.mouseleave(function(){
		$(this).hide().siblings("a").css("visibility","visible");	
	});
	//修改密码弹窗
    $("#reset_pswd").click(function (){
        $("#mask").toggle();
        $("#updateBox").toggle();
    });
    $("#confirm_cancel").click(function() {
        $("#mask").hide();
        $("#updateBox").hide();
        clearHtml();
    });
	
	
    //重置弹窗
    $("#confirm_ok").click(function() {
        $("#mask").hide();
        $("#popBox").hide();
    });
    $(".close").click(function() {
        $("#mask").hide();
        $("#exitBox").hide();
        $("#updateBox").hide();
        clearHtml();
    });
    //退出登录
    $("#exit_Login").click(function (){
       $("#mask").toggle(); 
       $("#exitBox").toggle();
    });
    $(".cancel_exit").click(function() {
        $("#mask").hide();
        $("#exitBox").hide();
    });
});

function clearHtml(){
	$("#errorMsg").html("");
	$("#oldpwd").val("");
	$("#newpwd").val("");
	$("#compwd").val("");
}

function updateLoginPwd(){
	$("#errorMsg").html("");
	var oldpwd = $("#oldpwd").val();
	var newpwd = $("#newpwd").val();
	var compwd = $("#compwd").val();
	if(oldpwd == null || oldpwd.length < 1){
		$("#errorMsg").html("");
		$("#errorMsg").append("原始密码不能为空");
		return;
	}	
	if(newpwd == null || newpwd.length < 1){
		$("#errorMsg").html("");
		$("#errorMsg").append("请输入新密码");
		return;
	}else{
		var reg = /^[A-Za-z0-9]{6,22}$/ ;
		if (!reg.test(newpwd)) {	
			$("#errorMsg").html("");
			$("#errorMsg").append(" 新密码输入有误,密码由6-22位字母、数字组成！");
			return;
		}
	}	
	if(compwd == null || compwd.length < 1){
		$("#errorMsg").html("");
		$("#errorMsg").append("请输入确认密码");
		return;
	}	
	if(compwd != newpwd){
		$("#errorMsg").html("");
		$("#errorMsg").append("两次输入密码不一致");
		return;
	}
	
	$.ajax({
		type: "POST",
		url: "${pageContext.request.contextPath}/operatorManagement/updateLoginPwd",
		dataType:"json",
		data: {
			oldPwd:oldpwd,
			newPwd:newpwd
		},
		success: function(data){			
			if (data.errorCode==0) {
				$("#oldpwd").val("");
				$("#newpwd").val("");
				$("#compwd").val("");
				$("#errorMsg").html("");
				$("#mask").hide();
		        $("#updateBox").hide();
		        prompt.alert(data.msg);
				loadResult(1,$("#selItem").val());
			}else{
				$("#errorMsg").html("");
				$("#errorMsg").append(data.msg);
			}
		}
	});	
}
</script>

